using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Zoo.DAL
{
	/// <summary>
	/// Strongly-typed collection for the ZooUser class.
	/// </summary>
	[Serializable]
	public partial class ZooUserCollection : ActiveList<ZooUser, ZooUserCollection> 
	{	   
		public ZooUserCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the ZooUsers table.
	/// </summary>
	[Serializable]
	public partial class ZooUser : ActiveRecord<ZooUser>
	{
		#region .ctors and Default Settings
		
		public ZooUser()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public ZooUser(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public ZooUser(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public ZooUser(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("ZooUsers", TableType.Table, DataService.GetInstance("ZooDB"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarUserID = new TableSchema.TableColumn(schema);
				colvarUserID.ColumnName = "UserID";
				colvarUserID.DataType = DbType.Int32;
				colvarUserID.MaxLength = 0;
				colvarUserID.AutoIncrement = true;
				colvarUserID.IsNullable = false;
				colvarUserID.IsPrimaryKey = true;
				colvarUserID.IsForeignKey = false;
				colvarUserID.IsReadOnly = false;
				colvarUserID.DefaultSetting = @"";
				colvarUserID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserID);
				
				TableSchema.TableColumn colvarUserLanguage = new TableSchema.TableColumn(schema);
				colvarUserLanguage.ColumnName = "UserLanguage";
				colvarUserLanguage.DataType = DbType.String;
				colvarUserLanguage.MaxLength = 10;
				colvarUserLanguage.AutoIncrement = false;
				colvarUserLanguage.IsNullable = false;
				colvarUserLanguage.IsPrimaryKey = false;
				colvarUserLanguage.IsForeignKey = false;
				colvarUserLanguage.IsReadOnly = false;
				colvarUserLanguage.DefaultSetting = @"";
				colvarUserLanguage.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserLanguage);
				
				TableSchema.TableColumn colvarNickName = new TableSchema.TableColumn(schema);
				colvarNickName.ColumnName = "NickName";
				colvarNickName.DataType = DbType.String;
				colvarNickName.MaxLength = 50;
				colvarNickName.AutoIncrement = false;
				colvarNickName.IsNullable = false;
				colvarNickName.IsPrimaryKey = false;
				colvarNickName.IsForeignKey = false;
				colvarNickName.IsReadOnly = false;
				colvarNickName.DefaultSetting = @"";
				colvarNickName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarNickName);
				
				TableSchema.TableColumn colvarEmailAddress = new TableSchema.TableColumn(schema);
				colvarEmailAddress.ColumnName = "EmailAddress";
				colvarEmailAddress.DataType = DbType.String;
				colvarEmailAddress.MaxLength = 150;
				colvarEmailAddress.AutoIncrement = false;
				colvarEmailAddress.IsNullable = false;
				colvarEmailAddress.IsPrimaryKey = false;
				colvarEmailAddress.IsForeignKey = false;
				colvarEmailAddress.IsReadOnly = false;
				colvarEmailAddress.DefaultSetting = @"";
				colvarEmailAddress.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEmailAddress);
				
				TableSchema.TableColumn colvarGender = new TableSchema.TableColumn(schema);
				colvarGender.ColumnName = "Gender";
				colvarGender.DataType = DbType.String;
				colvarGender.MaxLength = 1;
				colvarGender.AutoIncrement = false;
				colvarGender.IsNullable = false;
				colvarGender.IsPrimaryKey = false;
				colvarGender.IsForeignKey = false;
				colvarGender.IsReadOnly = false;
				colvarGender.DefaultSetting = @"";
				colvarGender.ForeignKeyTableName = "";
				schema.Columns.Add(colvarGender);
				
				TableSchema.TableColumn colvarSeeking = new TableSchema.TableColumn(schema);
				colvarSeeking.ColumnName = "Seeking";
				colvarSeeking.DataType = DbType.String;
				colvarSeeking.MaxLength = 1;
				colvarSeeking.AutoIncrement = false;
				colvarSeeking.IsNullable = false;
				colvarSeeking.IsPrimaryKey = false;
				colvarSeeking.IsForeignKey = false;
				colvarSeeking.IsReadOnly = false;
				colvarSeeking.DefaultSetting = @"";
				colvarSeeking.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSeeking);
				
				TableSchema.TableColumn colvarCountryID = new TableSchema.TableColumn(schema);
				colvarCountryID.ColumnName = "CountryID";
				colvarCountryID.DataType = DbType.Int32;
				colvarCountryID.MaxLength = 0;
				colvarCountryID.AutoIncrement = false;
				colvarCountryID.IsNullable = false;
				colvarCountryID.IsPrimaryKey = false;
				colvarCountryID.IsForeignKey = true;
				colvarCountryID.IsReadOnly = false;
				
						colvarCountryID.DefaultSetting = @"((0))";
				
					colvarCountryID.ForeignKeyTableName = "Countrys";
				schema.Columns.Add(colvarCountryID);
				
				TableSchema.TableColumn colvarRegionID = new TableSchema.TableColumn(schema);
				colvarRegionID.ColumnName = "RegionID";
				colvarRegionID.DataType = DbType.Int32;
				colvarRegionID.MaxLength = 0;
				colvarRegionID.AutoIncrement = false;
				colvarRegionID.IsNullable = false;
				colvarRegionID.IsPrimaryKey = false;
				colvarRegionID.IsForeignKey = true;
				colvarRegionID.IsReadOnly = false;
				
						colvarRegionID.DefaultSetting = @"((0))";
				
					colvarRegionID.ForeignKeyTableName = "Regions";
				schema.Columns.Add(colvarRegionID);
				
				TableSchema.TableColumn colvarBornDate = new TableSchema.TableColumn(schema);
				colvarBornDate.ColumnName = "BornDate";
				colvarBornDate.DataType = DbType.DateTime;
				colvarBornDate.MaxLength = 0;
				colvarBornDate.AutoIncrement = false;
				colvarBornDate.IsNullable = false;
				colvarBornDate.IsPrimaryKey = false;
				colvarBornDate.IsForeignKey = false;
				colvarBornDate.IsReadOnly = false;
				colvarBornDate.DefaultSetting = @"";
				colvarBornDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBornDate);
				
				TableSchema.TableColumn colvarCity = new TableSchema.TableColumn(schema);
				colvarCity.ColumnName = "City";
				colvarCity.DataType = DbType.String;
				colvarCity.MaxLength = 50;
				colvarCity.AutoIncrement = false;
				colvarCity.IsNullable = false;
				colvarCity.IsPrimaryKey = false;
				colvarCity.IsForeignKey = false;
				colvarCity.IsReadOnly = false;
				colvarCity.DefaultSetting = @"";
				colvarCity.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCity);
				
				TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
				colvarDescription.ColumnName = "Description";
				colvarDescription.DataType = DbType.String;
				colvarDescription.MaxLength = 1500;
				colvarDescription.AutoIncrement = false;
				colvarDescription.IsNullable = false;
				colvarDescription.IsPrimaryKey = false;
				colvarDescription.IsForeignKey = false;
				colvarDescription.IsReadOnly = false;
				colvarDescription.DefaultSetting = @"";
				colvarDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescription);
				
				TableSchema.TableColumn colvarRegistrationDate = new TableSchema.TableColumn(schema);
				colvarRegistrationDate.ColumnName = "RegistrationDate";
				colvarRegistrationDate.DataType = DbType.DateTime;
				colvarRegistrationDate.MaxLength = 0;
				colvarRegistrationDate.AutoIncrement = false;
				colvarRegistrationDate.IsNullable = false;
				colvarRegistrationDate.IsPrimaryKey = false;
				colvarRegistrationDate.IsForeignKey = false;
				colvarRegistrationDate.IsReadOnly = false;
				
						colvarRegistrationDate.DefaultSetting = @"(getdate())";
				colvarRegistrationDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRegistrationDate);
				
				TableSchema.TableColumn colvarLastLogin = new TableSchema.TableColumn(schema);
				colvarLastLogin.ColumnName = "LastLogin";
				colvarLastLogin.DataType = DbType.DateTime;
				colvarLastLogin.MaxLength = 0;
				colvarLastLogin.AutoIncrement = false;
				colvarLastLogin.IsNullable = false;
				colvarLastLogin.IsPrimaryKey = false;
				colvarLastLogin.IsForeignKey = false;
				colvarLastLogin.IsReadOnly = false;
				
						colvarLastLogin.DefaultSetting = @"(getdate())";
				colvarLastLogin.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLastLogin);
				
				TableSchema.TableColumn colvarOnline = new TableSchema.TableColumn(schema);
				colvarOnline.ColumnName = "Online";
				colvarOnline.DataType = DbType.Boolean;
				colvarOnline.MaxLength = 0;
				colvarOnline.AutoIncrement = false;
				colvarOnline.IsNullable = false;
				colvarOnline.IsPrimaryKey = false;
				colvarOnline.IsForeignKey = false;
				colvarOnline.IsReadOnly = false;
				
						colvarOnline.DefaultSetting = @"((0))";
				colvarOnline.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOnline);
				
				TableSchema.TableColumn colvarPassword = new TableSchema.TableColumn(schema);
				colvarPassword.ColumnName = "Password";
				colvarPassword.DataType = DbType.String;
				colvarPassword.MaxLength = 50;
				colvarPassword.AutoIncrement = false;
				colvarPassword.IsNullable = false;
				colvarPassword.IsPrimaryKey = false;
				colvarPassword.IsForeignKey = false;
				colvarPassword.IsReadOnly = false;
				colvarPassword.DefaultSetting = @"";
				colvarPassword.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPassword);
				
				TableSchema.TableColumn colvarEmailOptin = new TableSchema.TableColumn(schema);
				colvarEmailOptin.ColumnName = "EmailOptin";
				colvarEmailOptin.DataType = DbType.Boolean;
				colvarEmailOptin.MaxLength = 0;
				colvarEmailOptin.AutoIncrement = false;
				colvarEmailOptin.IsNullable = false;
				colvarEmailOptin.IsPrimaryKey = false;
				colvarEmailOptin.IsForeignKey = false;
				colvarEmailOptin.IsReadOnly = false;
				
						colvarEmailOptin.DefaultSetting = @"((0))";
				colvarEmailOptin.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEmailOptin);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["ZooDB"].AddSchema("ZooUsers",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("UserID")]
		public int UserID 
		{
			get { return GetColumnValue<int>("UserID"); }

			set { SetColumnValue("UserID", value); }

		}

		  
		[XmlAttribute("UserLanguage")]
		public string UserLanguage 
		{
			get { return GetColumnValue<string>("UserLanguage"); }

			set { SetColumnValue("UserLanguage", value); }

		}

		  
		[XmlAttribute("NickName")]
		public string NickName 
		{
			get { return GetColumnValue<string>("NickName"); }

			set { SetColumnValue("NickName", value); }

		}

		  
		[XmlAttribute("EmailAddress")]
		public string EmailAddress 
		{
			get { return GetColumnValue<string>("EmailAddress"); }

			set { SetColumnValue("EmailAddress", value); }

		}

		  
		[XmlAttribute("Gender")]
		public string Gender 
		{
			get { return GetColumnValue<string>("Gender"); }

			set { SetColumnValue("Gender", value); }

		}

		  
		[XmlAttribute("Seeking")]
		public string Seeking 
		{
			get { return GetColumnValue<string>("Seeking"); }

			set { SetColumnValue("Seeking", value); }

		}

		  
		[XmlAttribute("CountryID")]
		public int CountryID 
		{
			get { return GetColumnValue<int>("CountryID"); }

			set { SetColumnValue("CountryID", value); }

		}

		  
		[XmlAttribute("RegionID")]
		public int RegionID 
		{
			get { return GetColumnValue<int>("RegionID"); }

			set { SetColumnValue("RegionID", value); }

		}

		  
		[XmlAttribute("BornDate")]
		public DateTime BornDate 
		{
			get { return GetColumnValue<DateTime>("BornDate"); }

			set { SetColumnValue("BornDate", value); }

		}

		  
		[XmlAttribute("City")]
		public string City 
		{
			get { return GetColumnValue<string>("City"); }

			set { SetColumnValue("City", value); }

		}

		  
		[XmlAttribute("Description")]
		public string Description 
		{
			get { return GetColumnValue<string>("Description"); }

			set { SetColumnValue("Description", value); }

		}

		  
		[XmlAttribute("RegistrationDate")]
		public DateTime RegistrationDate 
		{
			get { return GetColumnValue<DateTime>("RegistrationDate"); }

			set { SetColumnValue("RegistrationDate", value); }

		}

		  
		[XmlAttribute("LastLogin")]
		public DateTime LastLogin 
		{
			get { return GetColumnValue<DateTime>("LastLogin"); }

			set { SetColumnValue("LastLogin", value); }

		}

		  
		[XmlAttribute("Online")]
		public bool Online 
		{
			get { return GetColumnValue<bool>("Online"); }

			set { SetColumnValue("Online", value); }

		}

		  
		[XmlAttribute("Password")]
		public string Password 
		{
			get { return GetColumnValue<string>("Password"); }

			set { SetColumnValue("Password", value); }

		}

		  
		[XmlAttribute("EmailOptin")]
		public bool EmailOptin 
		{
			get { return GetColumnValue<bool>("EmailOptin"); }

			set { SetColumnValue("EmailOptin", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public Zoo.DAL.InterestCollection Interests()
		{
			return new Zoo.DAL.InterestCollection().Where(Interest.Columns.UserID, UserID).Load();
		}

		public Zoo.DAL.PictureCollection Pictures()
		{
			return new Zoo.DAL.PictureCollection().Where(Picture.Columns.UserID, UserID).Load();
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Country ActiveRecord object related to this ZooUser
		/// 
		/// </summary>
		public Zoo.DAL.Country Country
		{
			get { return Zoo.DAL.Country.FetchByID(this.CountryID); }

			set { SetColumnValue("CountryID", value.CountryID); }

		}

		
		
		/// <summary>
		/// Returns a Region ActiveRecord object related to this ZooUser
		/// 
		/// </summary>
		public Zoo.DAL.Region Region
		{
			get { return Zoo.DAL.Region.FetchByID(this.RegionID); }

			set { SetColumnValue("RegionID", value.RegionID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varUserLanguage,string varNickName,string varEmailAddress,string varGender,string varSeeking,int varCountryID,int varRegionID,DateTime varBornDate,string varCity,string varDescription,DateTime varRegistrationDate,DateTime varLastLogin,bool varOnline,string varPassword,bool varEmailOptin)
		{
			ZooUser item = new ZooUser();
			
			item.UserLanguage = varUserLanguage;
			
			item.NickName = varNickName;
			
			item.EmailAddress = varEmailAddress;
			
			item.Gender = varGender;
			
			item.Seeking = varSeeking;
			
			item.CountryID = varCountryID;
			
			item.RegionID = varRegionID;
			
			item.BornDate = varBornDate;
			
			item.City = varCity;
			
			item.Description = varDescription;
			
			item.RegistrationDate = varRegistrationDate;
			
			item.LastLogin = varLastLogin;
			
			item.Online = varOnline;
			
			item.Password = varPassword;
			
			item.EmailOptin = varEmailOptin;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varUserID,string varUserLanguage,string varNickName,string varEmailAddress,string varGender,string varSeeking,int varCountryID,int varRegionID,DateTime varBornDate,string varCity,string varDescription,DateTime varRegistrationDate,DateTime varLastLogin,bool varOnline,string varPassword,bool varEmailOptin)
		{
			ZooUser item = new ZooUser();
			
				item.UserID = varUserID;
				
				item.UserLanguage = varUserLanguage;
				
				item.NickName = varNickName;
				
				item.EmailAddress = varEmailAddress;
				
				item.Gender = varGender;
				
				item.Seeking = varSeeking;
				
				item.CountryID = varCountryID;
				
				item.RegionID = varRegionID;
				
				item.BornDate = varBornDate;
				
				item.City = varCity;
				
				item.Description = varDescription;
				
				item.RegistrationDate = varRegistrationDate;
				
				item.LastLogin = varLastLogin;
				
				item.Online = varOnline;
				
				item.Password = varPassword;
				
				item.EmailOptin = varEmailOptin;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string UserID = @"UserID";
			 public static string UserLanguage = @"UserLanguage";
			 public static string NickName = @"NickName";
			 public static string EmailAddress = @"EmailAddress";
			 public static string Gender = @"Gender";
			 public static string Seeking = @"Seeking";
			 public static string CountryID = @"CountryID";
			 public static string RegionID = @"RegionID";
			 public static string BornDate = @"BornDate";
			 public static string City = @"City";
			 public static string Description = @"Description";
			 public static string RegistrationDate = @"RegistrationDate";
			 public static string LastLogin = @"LastLogin";
			 public static string Online = @"Online";
			 public static string Password = @"Password";
			 public static string EmailOptin = @"EmailOptin";
						
		}

		#endregion
	}

}

